import axios from 'axios'

let bUrl = 'http://api.cat-shop.penkuoer.com'
axios.defaults.headers.common['Authorization'] = "Bearer " + localStorage.getItem('token')


export const get = (url, params) => {
    var url = bUrl + url
    return axios.get(url, params).then(res => {
        // console.log(res)
        return res
    })
}

export const post = (url, data) => {
    var url = bUrl + url
    return axios.post(url, data).then(res => {
        console.log(res)

        if (!localStorage.getItem("token")) {
            localStorage.setItem('token', res.data.token)
        }
        return res
    })
}

export const put = (url, params) => {
    var url = bUrl + url
    return axios.put(url, params).then(res => {
        console.log(res)
        return res
    })
}

export const DELETE = (url, params) => {
    var url = bUrl + url
    return axios.delete(url, params).then(res => {
        console.log(res)
        return res
    })
}
